home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.06 Jun 95 / Apple Events in PowerPlant / Powering Up Code / SCApp.cp next >
Encoding:
Text File  |  1995-04-05  |  2.5 KB  |  123 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. // SCApp.cp
  3. // ===========================================================================
  4. // © 1995 James Kaput, Jeremy Roschelle SimCalc Project
  5.  
  6. #include "SCApp.h"
  7. #include "SCDoc.h"
  8. #include "SCModelProperty.h"
  9.  
  10. long SCApp::sUniqueID = 100;
  11. SCSetPropertyAction    *SCApp::sAction = nil;
  12.  
  13. void main(void)
  14. {
  15.                                     // Set Debugging options
  16. #ifdef Debug_Throw
  17.     gDebugThrow = debugAction_Nothing; // or debugAction_SourceDebugger
  18. #endif
  19.  
  20. #ifdef Debug_Signal
  21.     gDebugSignal = debugAction_Nothing;
  22. #endif
  23.  
  24.     InitializeHeap(4);
  25.     InitializeToolbox();
  26.             
  27.     SCApp    theApp;
  28.     theApp.Run();
  29. }
  30.  
  31. void
  32. SCApp::StartUp()
  33. {    
  34.     new SCDoc(this);
  35. }
  36.  
  37. long 
  38. SCApp::GenerateUniqueID()
  39. {
  40.     return ++sUniqueID;
  41. }
  42.  
  43. // note: we can't use LSemanticUndoer for its PostAction, ObeyCommand, and FindCommandStatus
  44. // because LSemanticUndoer has no provision for getting an Undo string from any place but a
  45. // STR# resource, and we are constructing strings from the 'aete' properties.
  46. // this code below is mostly copied from LSemanticUndoer, but changed to ease this restriction
  47.  
  48. // in a real application, you would define a more general class than SCSetPropertyAction
  49. // and be able to Post all actions of that class
  50.  
  51. void    
  52. SCApp::PostAction(SCSetPropertyAction *inAction)
  53. {
  54.     delete sAction;
  55.     sAction = inAction;
  56.     sAction->Redo();
  57. }
  58.  
  59. Boolean    
  60. SCApp::ObeyCommand(
  61.     CommandT    inCommand,
  62.     void        *ioParam)
  63. {
  64.     switch (inCommand) {
  65.     
  66.         case cmd_Undo:
  67.             Assert_(sAction);
  68.             if (sAction->CanRedo() || sAction->CanUndo()) {
  69.                 if (sAction->CanUndo())
  70.                     sAction->Undo();
  71.                 else
  72.                     sAction->Redo();
  73.             }
  74.             return true;
  75.             break;
  76.             
  77.         default:
  78.             return inherited::ObeyCommand(inCommand, ioParam);
  79.             break;
  80.     }
  81.     return false;
  82. }
  83.  
  84. void    
  85. SCApp::FindCommandStatus(
  86.     CommandT    inCommand,
  87.     Boolean        &outEnabled,
  88.     Boolean        &outUsesMark,
  89.     Char16        &outMark,
  90.     Str255        outName)
  91. {
  92.     switch (inCommand) {
  93.  
  94.         case cmd_Undo:
  95.             outEnabled = false;
  96.             if (sAction) {
  97.                 Str255    prop;
  98.                 if (sAction->CanRedo()) {
  99.                     outEnabled = true;
  100.                     CopyPStr("\pRedo ",outName);
  101.                     sAction->GetDescriptor(prop);
  102.                     ConcatPStr(outName,prop);
  103.                 } else if (sAction->CanUndo()) {
  104.                     outEnabled = true;
  105.                     CopyPStr("\pUndo ",outName);
  106.                     sAction->GetDescriptor(prop);
  107.                     ConcatPStr(outName,prop);
  108.                 }
  109.             }
  110.  
  111.             if (!outEnabled) {
  112.                 GetIndString(outName, STRx_Standards, str_CantUndo);
  113.                 ThrowIfResError_();
  114.             }
  115.             break;
  116.  
  117.         default:
  118.             inherited::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  119.             break;
  120.  
  121.     }
  122. }
  123.